package com.bjc.netty.http;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 * @program: nettypro
 * @description:
 * @author: bjc
 * @create: 2021-09-09 22:03
 */
public class TestServer {

    public static void main(String[] args) throws InterruptedException {
        //设置bossGroup数量为1
        EventLoopGroup bossGroup = new NioEventLoopGroup(1);
        EventLoopGroup workerGroup = new NioEventLoopGroup();

        try {
            ServerBootstrap serverBootstrap = new ServerBootstrap();

            serverBootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(new TestServerInitializer());

            /**
             * 在写netty的http server的例子过程中，但是一直发现浏览器使用端口号6668一直无法连接，使用postman就可以连接。
             * 通过查找资料发现6668端口是被浏览器认为不安全的端口，6666~6669这几个端口是IRC协议使用的缺省端口，存在很大的风险，很容易被木马程序利用.
             */
            ChannelFuture channelFuture = serverBootstrap.bind(668).sync();

            channelFuture.channel().closeFuture().sync();

        } finally {
            bossGroup.shutdownGracefully();
            workerGroup.shutdownGracefully();
        }
    }
}
